package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/08/23 21:15
 **/
public class Day38_4_Num91_NumDecodings {
    class Solution {
        public int numDecodings(String s) {
            if(s.length() == 0) return 0;
            int[] dp = new int[s.length()+1]; dp[0] = 1;
            char[] str = s.toCharArray();
            for(int i = 0; i < dp.length; ++i){
                dp[i+1] = str[i] == '0'? 0 : dp[i];
                if(i > 0 && (str[i-1] == '1' || str[i-1] == '2' && str[i] <= '6')){
                    dp[i+1] += dp[i-1];
                }
            }
            return dp[dp.length-1];
        }
    }
}